/*
 * Created on 28/09/2006
 *
 */
package org.mushroomdb.query.impl;

import java.util.Iterator;
import java.util.List;

import org.mushroomdb.catalog.Column;
import org.mushroomdb.catalog.impl.FillableRegister;
import org.mushroomdb.engine.EvaluationEngine;
import org.mushroomdb.engine.impl.ObjectArrayResultSet;


/**
 * @author mchiodi
 */
public class LiteralsSelectionQuery extends SelectionQuery {
	private List columns;
	
	/**
	 * Default constructor
	 */
	public LiteralsSelectionQuery(List columns) {
		super();
		this.columns = columns;
	}

	/**
	 * @see org.mushroomdb.query.Query#execute(org.mushroomdb.engine.EvaluationEngine)
	 */
	public Object execute(EvaluationEngine evaluationEngine) {
		
		/* Add columns */
		FillableRegister register = new FillableRegister();
		Iterator iterator = this.columns.listIterator();
		while (iterator.hasNext()) {
			register.addColumn((Column) iterator.next());
		}
		
		/* Fill literals */
		iterator = this.getProjections();
		int i = 1;
		while (iterator.hasNext()) {
			register.setValue(i,iterator.next());
			i++;
		}
		
		return new ObjectArrayResultSet(new Object[] {register});
	}
}
